/*
 * @Author: 岸舟
 * @Date: 2020-09-22 16:04:08
 * @LastEditors: 岸舟
 * @LastEditTime: 2020-09-23 18:49:17
 * @Description: 
 */

import apis from '../../http/apis/apis'

export default {
  namespaced: true,
  state: {
        insureSorts:[],
        backendVal:""
  },
  mutations: {
      setIsureSorts(state,val){
          state.insureSorts = val
      },
      setBackendVal(state,val){
        state.backendVal = val
      }
  },
  actions:{
      async getSorts(context){
          const data = await apis.insureSortApi.getSortsApi()
          if (data.status){
              context.commit("setIsureSorts",{data:data.data.data})
          }
      },
      async modSort(context,val){
        await apis.insureSortApi.modSortName(val._id,val.sortName)
        context.dispatch("getSorts")
      },
      async delSort(context,sortName){
        await apis.insureSortApi.delSortOne(sortName)
        context.dispatch("getSorts")
      },
      async addSort(context,newSort){
        const data = await apis.insureSortApi.addSortOne(newSort)
        context.commit("setBackendVal",data.data)
        context.dispatch("getSorts")
      }
  }
}
